import React, {useReducer} from 'react';
import PropTypes from 'prop-types';

const Index = props => {
    const xinXi={
        count:0
    }
    function fun(state,action) {
        console.log(state)
        console.log(action)
        switch (action.type) {
            case 'increment':
                return {count: state.count + 1};
            case 'decrement':
                return {count: state.count - 1};
            default:
                throw new Error();
        }
    }
    const [state,setState]=useReducer(fun,xinXi)
    return (
        <div>
            {state.count}
            <button onClick={()=>{
                setState({type:'increment'})
            }}> add</button>
            <button onClick={()=>{
                setState({type:'decrement'})
            }}> --</button>
        </div>
    );
};

Index.propTypes = {

};

export default Index;
